#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;

void func()
{
    cout << "hello func" << endl;
}

void test()
{
    int a = 100;
    //[]捕获列表
    //()函数的参数列表
    //{}函数的函数体
    []()->void{
        cout << "hello" << endl;
    }();

    //lambda表达式默认是const的，如果想修改可以使用mutable
    //值捕获
    [a]()mutable->void{
        ++a;
        cout << "a = " << a << endl;
        cout << "hello" << endl;
    }();

    //引用捕获
    [&a]()->void{
        ++a;
        cout << "a = " << a << endl;
        cout << "hello" << endl;
    }();
    cout << "-----a = " << a << endl;
}

void test2()
{
    [](const string &name){
        cout << "test2" << endl;
        cout << "name = " << name <<endl;
    }("wangdao");

    cout << endl << endl;
    auto f = [](const string &name){
        cout << "test2" << endl;
        cout << "name = " << name <<endl;
    };
    f("test");

    cout << endl << endl;
    typedef void (*pFunc)(const string &);//C
    /* using pFunc = void(const string &);//C++ */
    pFunc pf = [](const string &name){
        cout << "test2" << endl;
        cout << "name = " << name <<endl;
    };

    pf("wangdao wuhan");
}

int main(int argc, char *argv[])
{
    test2();
    return 0;
}

